package com.zytech.zspider.transformer;

import com.zytech.zspider.core.BadSpiderDefinitionException;
import org.antlr.v4.runtime.DiagnosticErrorListener;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;

/**
 * @author siuming
 */
final class SpiderDefinitionTransformerErrorListener extends DiagnosticErrorListener {

    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) {
        throw new BadSpiderDefinitionException(
                String.format(
                        "[line:%d,pos:%d] %s",
                        line,
                        charPositionInLine,
                        msg
                )
        );
    }
}
